package shujia.day15;

/*
    休眠线程 sleep(10000)
    中断线程 stop() | interrupt() 推荐使用interrupt(); 因为stop将整个线程终止不再执行，而 interrupt() 会继续执行后续代码
 */
class MyThread3 extends Thread{
    @Override
    public void run() {
        System.out.println(getName()+" 睡觉了....");
        try {
            Thread.sleep(10000);  // 10s  阻塞
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(getName()+" 睡醒了....");
    }
}

public class ThreadSleepDemo1 {
    public static void main(String[] args) {
        MyThread3 t1 = new MyThread3();
        t1.setName("张成阳");

        t1.start();

        try {
            Thread.sleep(5000);
//            t1.stop(); // 终止t1线程的执行
            t1.interrupt();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
